package com.ruijie.acl;

import com.ruijie.emp.device.Device;
import com.ruijie.emp.device.DeviceInterface;
import com.ruijie.foundation.adapter.utils.StringUtils;
import com.ruijie.foundation.bo.EntityObject;

/**
 * <p>
 * Title: 设备接口ACL设置对象
 * </p>
 * <p>
 * Description: 用于数据库中的设备接口ACL设置管理
 * </p>
 * <p>
 * Copyright: Copyright (c) 2008
 * </p>
 * <p>
 * Company: Ruijie Co., Ltd.
 * </p>
 * <p>
 * Create Time: 2009-09-14
 * </p>
 * <p>
 * Update Time:
 * </p>
 * <p>
 * Updater:
 * </p>
 * <p>
 * Update Comments:
 * </p>
 *@author ASAI
 */
public class AclInterface extends EntityObject {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = -8804048324049174890L;
	private AccessGroup outAccessGroup;
	private DeviceInterface deviceInterface;
	private AccessGroup inAccessGroup;
	private Device device;
	
	private String outAccessGroupName;
	private String inAccessGroupName;

	public AclInterface() {
	}

	public DeviceInterface getDeviceInterface() {
		return deviceInterface;
	}

	public void setDeviceInterface(DeviceInterface deviceInterface) {
		this.deviceInterface = deviceInterface;
	}

	public Device getDevice() {
		return device;
	}

	public void setDevice(Device device) {
		this.device = device;
	}

	public AccessGroup getOutAccessGroup() {
		return outAccessGroup;
	}

	public void setOutAccessGroup(AccessGroup outAccessGroup) {
		this.outAccessGroup = outAccessGroup;
	}

	public AccessGroup getInAccessGroup() {
		return inAccessGroup;
	}

	public void setInAccessGroup(AccessGroup inAccessGroup) {
		this.inAccessGroup = inAccessGroup;
	}

	public String getOutAccessGroupName() {
		return outAccessGroupName;
	}

	public void setOutAccessGroupName(String outAccessGroupName) {
		this.outAccessGroupName = outAccessGroupName;
	}

	public String getInAccessGroupName() {
		return inAccessGroupName;
	}

	public void setInAccessGroupName(String inAccessGroupName) {
		this.inAccessGroupName = inAccessGroupName;
	}
	
	public boolean isDisplayOut(){
		boolean result = false;
		if (outAccessGroup != null && inAccessGroup != null){
			if (outAccessGroup.getId().longValue() == inAccessGroup.getId().longValue()){
				result = false;
			}else{
				result = true;
			}
		}
		return result;
	}
	
	/**
	 * 取得字符串
	 * @param inFlag 是否为In
	 * @return
	 */
	public String toString(boolean inFlag) {
		String resultString = "";
		if (deviceInterface != null){
			resultString += deviceInterface.getName() + "(" + deviceInterface.getIfDescr()+")";
		}
		if (outAccessGroup != null && inAccessGroup != null){
			if (outAccessGroup.getId().longValue() == inAccessGroup.getId().longValue()){
				resultString += " [In,Out]   " + outAccessGroup.getName();
			}else if (inFlag){
				resultString += " [In]   " + inAccessGroup.getName();
			}else{
				resultString += " [Out]   " + outAccessGroup.getName();
			}
		}else if (outAccessGroup != null){
			resultString += " [Out]   " + outAccessGroup.getName() ;
		}else if (inAccessGroup != null){
			resultString += " [In]   " + inAccessGroup.getName();
		}else{
			if (!StringUtils.isNullOrEmpty(inAccessGroupName)&& 
					!StringUtils.isNullOrEmpty(outAccessGroupName)){
				resultString += " [In,Out]   " + outAccessGroupName;
			}else if (!StringUtils.isNullOrEmpty(inAccessGroupName)) {
				resultString += " [In]   " + inAccessGroupName;
			}else if (!StringUtils.isNullOrEmpty(outAccessGroupName)) {
				resultString += " [Out]   " + outAccessGroupName;
			}
		}
		
		return resultString;
	}
	
	/**
	 * 取得字符串
	 * @param inFlag 是否为In
	 * @return
	 */
	public String toValueString() {
		String resultString = "";
		if (deviceInterface != null){
			resultString += deviceInterface.getId() + ",";
		}
				
		if (this.inAccessGroup != null && this.outAccessGroup != null) {
			resultString += "InOut," + inAccessGroup.getId() + ";";
		}else if (inAccessGroup != null) {
			resultString += "In," + inAccessGroup.getId() + ";";
		}else if (outAccessGroup != null) {
			resultString += "Out," +outAccessGroup.getId() + ";";
		}else{
			if (!StringUtils.isNullOrEmpty(inAccessGroupName)&& 
					!StringUtils.isNullOrEmpty(outAccessGroupName)){
				resultString += "InOut,-1;";
			}else if (!StringUtils.isNullOrEmpty(inAccessGroupName)) {
				resultString += "In,-1;";
			}else if (!StringUtils.isNullOrEmpty(outAccessGroupName)) {
				resultString += "Out,-1;";
			}
		}
		
		return resultString;
	}

}
